package com.ssyc.gsk_teacher_appraisal.fragment;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.ssyc.common.base.LazyBaseFragment;
import com.ssyc.common.manager.BqaManager;
import com.ssyc.gsk_teacher_appraisal.R;
import com.ssyc.gsk_teacher_appraisal.adapter.ChooseTestRvAdapter;
import com.ssyc.gsk_teacher_appraisal.bean.ChooseTestInfo;

import java.util.ArrayList;
import java.util.List;


/**
 * 选择套题列表界面
 * Created by Kevin on 2018/11/13.
 */

public class TkTeacherChooseTestFragment extends LazyBaseFragment {

    private int currPos;

    private ChooseTestInfo questionInfo;

    private List<ChooseTestInfo.ListBean> datas;

    private RecyclerView rv;

    //空视图
    private View emptyView;

    //适配器
    private ChooseTestRvAdapter adapter;


    public static TkTeacherChooseTestFragment newInstance(ChooseTestInfo data,int currPos) {
        TkTeacherChooseTestFragment TkTeacherChooseTestFragment = new TkTeacherChooseTestFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("data",data);
        bundle.putInt("curr", currPos);
        TkTeacherChooseTestFragment.setArguments(bundle);
        return TkTeacherChooseTestFragment;
    }

    @Override
    public void lazyInit(View view, Bundle savedInstanceState) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_tk_teacher_choose_test;
    }

    @Override
    protected boolean isNeedShowTitle() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return null;
    }

    @Override
    protected void init(View view, Bundle savedInstanceState) {
        super.init(view, savedInstanceState);

        showContent();

        //获取传递的数据
        initIntent();

        //初始化
        initView(view);

        //设置列表
        initRv();
    }

    /**
     * 初始化
     */
    private void initView(View view) {

        rv = view.findViewById(R.id.rv);

    }


    /**
     * 获取传递的数据
     */
    private void initIntent() {

        //获取位置
        currPos = getArguments().getInt("curr");

        //获取列表
        questionInfo = (ChooseTestInfo) getArguments().getSerializable("data");

        if(questionInfo!=null){
            if(currPos<questionInfo.getList().size()){
                datas = questionInfo.getList().get(currPos);
            }else{
                datas = new ArrayList<>();
            }
        }else{
            datas = new ArrayList<>();
        }


    }

    /**
     * 设置列表
     */
    private void initRv() {

        emptyView = View.inflate(getActivity(), R.layout.base_rv_common_empty_view_white_bg, null);
        TextView tvMessage = emptyView.findViewById(R.id.tv_content);
        tvMessage.setText("暂无数据");
        adapter = new ChooseTestRvAdapter(getActivity(), R.layout.teacher_rv_choose_test, datas);

        BqaManager.setRv(emptyView, getActivity(), adapter, rv, null);
    }
}
